//
//  GetPhoneInfo.m
//  SocretTest
//
//  Created by ellenpage on 12-11-26.
//  Copyright (c) 2012年 ellenpage. All rights reserved.
//

#import "Reachability.h"
#import "GetPhoneInfo.h"
#import "UIDevice+IdentifierAddition.h"
#import <CoreLocation/CLAvailability.h>
#import "OpenUDID.h"
#import "Constant.h"

@implementation GetPhoneInfo

+ (NSString *)getCurrentNetworkStatus
{
    NSString* result;
    
    Reachability *r = [Reachability reachabilityWithHostName:@"www.baidu.com"];
    
    switch ([r currentReachabilityStatus])
    {
        case NotReachable:// 没有网络连接
        {
            result=@"no";
            break;
        }
        case ReachableViaWWAN:// 使用3G网络
        {
            result=@"3g";
            break;
        }
        case ReachableViaWiFi:// 使用WiFi网络
        {
            result=@"wifi";
            break;
        }
    }
    return result;
}

+ (NSString *)getCurrentDevice
{
    NSString *model = [[UIDevice currentDevice] model];
    return model;
}

+ (NSString *)getCurrentSystemVersion
{
    NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
    return systemVersion;
}

+ (NSString *)getCurrentTimeStamp
{
    NSDate *timer1011=[NSDate date];
	NSDateFormatter *dateformatter1011=[[NSDateFormatter alloc] init];
	[dateformatter1011 setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [dateformatter1011 setTimeZone:timeZone];
    
//	NSString *timenow1011=[dateformatter1011 stringFromDate:timer1011];

    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[timer1011 timeIntervalSince1970]];
    NSLog(@"%@",timeSp);
    return timeSp;
}

+ (NSString *)getRealTimeStamp
{
    NSDate *timer1011=[NSDate date];
	NSDateFormatter *dateformatter1011=[[NSDateFormatter alloc] init];
	[dateformatter1011 setDateFormat:@"YYYY-MM-dd HH:mm:ss"];

    NSString *timenow1011 = [dateformatter1011 stringFromDate:timer1011];
    return timenow1011;
}


+ (NSString *)getCurrentOperatorName
{
    CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = info.subscriberCellularProvider;
    NSLog(@"%@",[carrier carrierName]);
    return [carrier carrierName];
}

+ (NSString *)getCurrentOperatorStr:(NSString *)operatorName
{
   NSString *operatorNum;
    
    if ([operatorName isEqualToString:@"中国电信"])
    {
        operatorNum = @"46003";
        return operatorNum;
    }
    else if([operatorName isEqualToString:@"中国联通"])
    {
        operatorNum = @"46001";
        return operatorNum;
    }
    else if ([operatorName isEqualToString:@"中国移动"])
    {
        operatorNum = @"46000";
        return operatorNum;
    }
    else
    {
        return @"46003";//非运营商网络
    }
}

+ (NSString *)getCurrentIMSI
{
    NSString *operatorNameStr = [GetPhoneInfo getCurrentOperatorName];
    NSString *operatorNumStr  = [GetPhoneInfo getCurrentOperatorStr:operatorNameStr];
    
    NSString *imsiStr = [operatorNumStr stringByAppendingFormat:@"%@",[GetPhoneInfo getCurrentMacAddress]];
    NSLog(@"%@",imsiStr);

    return imsiStr;
}

+ (NSString *)getCurrentMacAddress
{
   NSString *str = [mUserDefaults objectForKey:kUUID];
    if ([str length] > 0)
    {
        return str;
    }
    else
    {
        str = [GetPhoneInfo getCurrentTimeStamp];
        [mUserDefaults setObject:str forKey:kUUID];
        return str;
    }
}

+ (NSString *)get_uuid
{
    CFUUIDRef uuid_ref = CFUUIDCreate(NULL);
    CFStringRef uuid_string_ref= CFUUIDCreateString(NULL, uuid_ref);
    CFRelease(uuid_ref);
    NSString *uuid = [NSString stringWithString:(__bridge NSString*)uuid_string_ref];
    CFRelease(uuid_string_ref);
    return uuid;
}


@end
